RKMEDIA_SITE = $(TOPDIR)/../external/rkmedia
RKMEDIA_SITE_METHOD = local

RKMEDIA_INSTALL_STAGING = YES

RKMEDIA_DEPENDENCIES = host-ninja

RKMEDIA_CONF_OPTS = -DWARNINGS_AS_ERRORS=ON

ifeq ($(BR2_PACKAGE_RKMEDIA_MPP),y)
RKMEDIA_DEPENDENCIES += mpp
RKMEDIA_CONF_OPTS += -DRKMPP=ON \
	-DRKMPP_HEADER_DIR=$(STAGING_DIR)/usr/include/rockchip \
	-DRKMPP_LIB_NAME=rockchip_mpp
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_MPP_ENCODER),y)
RKMEDIA_CONF_OPTS += -DRKMPP_ENCODER=ON
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_MPP_DECODER),y)
RKMEDIA_CONF_OPTS += -DRKMPP_DECODER=ON
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_OGG),y)
RKMEDIA_CONF_OPTS += -DOGG=ON
endif

BR2_PACKAGE_RKMEDIA_OGGVORBIS =
ifeq ($(BR2_PACKAGE_RKMEDIA_OGGVORBIS_DEMUXER),y)
BR2_PACKAGE_RKMEDIA_OGGVORBIS=y
RKMEDIA_CONF_OPTS += -DOGGVORBIS=ON -DOGGVORBIS_DEMUXER=ON
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_OGGVORBIS_MUXER),y)
BR2_PACKAGE_RKMEDIA_OGGVORBIS=y
RKMEDIA_CONF_OPTS += -DOGGVORBIS=ON -DOGGVORBIS_MUXER=ON
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_OGGVORBIS),y)
RKMEDIA_DEPENDENCIES += libvorbis
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_ALSA_PLAYBACK),y)
RKMEDIA_CONF_OPTS += -DALSA_PLAYBACK=ON
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_ALSA_CAPTURE),y)
RKMEDIA_CONF_OPTS += -DALSA_CAPTURE=ON
endif

ifneq ($(BR2_PACKAGE_RKMEDIA_ALSA_PLAYBACK)$(BR2_PACKAGE_RKMEDIA_ALSA_CAPTURE),)
RKMEDIA_DEPENDENCIES += alsa-lib
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_V4L2_CAPTURE),y)
ifeq ($(BR2_PACKAGE_LIBV4L2),y)
RKMEDIA_DEPENDENCIES += libv4l
endif
RKMEDIA_CONF_OPTS += -DV4L2_CAPTURE=ON
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_RKRGA),y)
RKMEDIA_DEPENDENCIES += linux-rga
RKMEDIA_CONF_OPTS += -DRKRGA=ON
endif

ifeq ($(BR2_PACKAGE_DRM_DISPLAY_OUTPUT),y)
RKMEDIA_DEPENDENCIES += libdrm
RKMEDIA_CONF_OPTS += -DDRM_DISPLAY=ON
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_LIVE555),y)
RKMEDIA_CONF_OPTS += -DLIVE555=ON \
	-DGROUPSOCK_HEADER_DIR=$(STAGING_DIR)/usr/include/groupsock \
	-DUSAGEENVIRONMENT_HEADER_DIR=$(STAGING_DIR)/usr/include/UsageEnvironment
RKMEDIA_DEPENDENCIES += live555
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_RTSP_SERVER),y)
RKMEDIA_CONF_OPTS += -DLIVE555_SERVER=ON
endif

ifeq ($(BR2_PACKAGE_RKMEDIA_RTSP_SERVER_H264),y)
RKMEDIA_CONF_OPTS += -DLIVE555_SERVER_H264=ON
endif

RKMEDIA_CONF_OPTS += -G Ninja

RKMEDIA_NINJA_OPTS += $(if $(VERBOSE),-v) -j$(PARALLEL_JOBS)

define RKMEDIA_BUILD_CMDS
$(TARGET_MAKE_ENV) $($(PKG)_MAKE_ENV) ninja $($(PKG)_NINJA_OPTS) -C $($(PKG)_BUILDDIR)
endef

define RKMEDIA_INSTALL_TARGET_CMDS
$(TARGET_MAKE_ENV) DESTDIR=$(TARGET_DIR) ninja $($(PKG)_NINJA_OPTS) -C $($(PKG)_BUILDDIR) install
endef

define RKMEDIA_INSTALL_STAGING_CMDS
$(TARGET_MAKE_ENV) DESTDIR=$(STAGING_DIR) ninja $($(PKG)_NINJA_OPTS) -C $($(PKG)_BUILDDIR) install
endef

$(eval $(cmake-package))
